Namespace Logging
    Public Enum MessageType
        UI
        NameVer
        General
        NGSyncro
        ConnTrace
        FeedsList
        NetworkLayer
        FeedSync_Queue
        UpdateEngine_DL
        FeedEngine_FMSF
        UpdateEngine_UI
        FeedSync_Service
        FeedEngine_Loading
        FeedEngine_Parsing
        UpdateEngine_Parsing
    End Enum
    Public Enum HighestShowableMsg
        UI
        All
        Trace
        FeedSync
        NGSyncro
        FeedEngine
        NetworkLayer
        UpdateEngine
        FeedsListLoad
    End Enum
    Public Class LoggerMain
        Implements CoreFX.Interfaces.ILogging
        Public HighestShownMsg As HighestShowableMsg
        Dim UseFile As Boolean = Nothing
        Dim DBLForm As Object
        Delegate Sub AddText(ByVal Msg As String)
        Public Sub New(ByVal HSM As HighestShowableMsg)
#If DEBUG Then
            DBLForm = New Logging.DebugLogForm
            DBLForm.Show()
#End If
            HighestShownMsg = HSM
        End Sub
        Sub AddItem(ByVal Text As String, ByVal MessageType As Logging.MessageType) Implements Interfaces.ILogging.AddItem
            Try
                If IO.File.Exists(API.GetDataPath() & "mcdebug.log") = False Then
                    FileOpen(1, API.GetDataPath() & "mcdebug.log", OpenMode.Output)
                Else
                    FileOpen(1, API.GetDataPath() & "mcdebug.log", OpenMode.Append)
                End If
                WriteLine(1, Text)
                FileClose(1)
                Select Case HighestShownMsg
                    Case HighestShowableMsg.Trace
                        Select Case MessageType
                            Case Logging.MessageType.ConnTrace
                                If Not IsNothing(DBLForm) Then DBLForm.TextBox1.BeginInvoke(New AddText(AddressOf AddItem1), New String() {Text})
                            Case Logging.MessageType.NameVer
                                If Not IsNothing(DBLForm) Then DBLForm.TextBox1.BeginInvoke(New AddText(AddressOf AddItem1), New String() {Text})
                        End Select
                    Case HighestShowableMsg.All
                        If Not IsNothing(DBLForm) Then DBLForm.TextBox1.BeginInvoke(New AddText(AddressOf AddItem1), New String() {Text})
                    Case HighestShowableMsg.FeedSync
                        Select Case MessageType
                            Case Logging.MessageType.FeedSync_Queue
                                If Not IsNothing(DBLForm) Then DBLForm.TextBox1.BeginInvoke(New AddText(AddressOf AddItem1), New String() {Text})
                            Case Logging.MessageType.FeedSync_Service
                                If Not IsNothing(DBLForm) Then DBLForm.TextBox1.BeginInvoke(New AddText(AddressOf AddItem1), New String() {Text})
                        End Select
                    Case HighestShowableMsg.NetworkLayer
                        Select Case MessageType
                            'Case Logging.MessageType.General
                            '   If Not IsNothing(DBLForm) Then DBLForm.TextBox1.BeginInvoke(New AddText(AddressOf AddItem1), New String() {Text})
                            Case Logging.MessageType.NetworkLayer
                                If Not IsNothing(DBLForm) Then DBLForm.TextBox1.BeginInvoke(New AddText(AddressOf AddItem1), New String() {Text})
                        End Select
                    Case HighestShowableMsg.FeedEngine
                        Select Case MessageType
                            Case Logging.MessageType.FeedEngine_Loading
                                If Not IsNothing(DBLForm) Then DBLForm.TextBox1.BeginInvoke(New AddText(AddressOf AddItem1), New String() {Text})
                            Case Logging.MessageType.FeedEngine_Parsing
                                If Not IsNothing(DBLForm) Then DBLForm.TextBox1.BeginInvoke(New AddText(AddressOf AddItem1), New String() {Text})
                            Case Logging.MessageType.FeedEngine_FMSF
                                If Not IsNothing(DBLForm) Then DBLForm.TextBox1.BeginInvoke(New AddText(AddressOf AddItem1), New String() {Text})
                            Case Logging.MessageType.General
                                '      If Not IsNothing(DBLForm) Then DBLForm.TextBox1.BeginInvoke(New AddText(AddressOf AddItem1), New String() {Text})
                        End Select
                    Case HighestShowableMsg.NGSyncro
                        Select Case MessageType
                            Case Logging.MessageType.NGSyncro
                                If Not IsNothing(DBLForm) Then DBLForm.TextBox1.BeginInvoke(New AddText(AddressOf AddItem1), New String() {Text})
                            Case Logging.MessageType.General
                                If Not IsNothing(DBLForm) Then DBLForm.TextBox1.BeginInvoke(New AddText(AddressOf AddItem1), New String() {Text})
                        End Select
                    Case HighestShowableMsg.FeedsListLoad
                        Select Case MessageType
                            Case Logging.MessageType.FeedsList
                                If Not IsNothing(DBLForm) Then DBLForm.TextBox1.BeginInvoke(New AddText(AddressOf AddItem1), New String() {Text})
                                ' Case Logging.MessageType.General
                                '    If Not IsNothing(DBLForm) Then DBLForm.TextBox1.BeginInvoke(New AddText(AddressOf AddItem1), New String() {Text})
                        End Select
                    Case HighestShowableMsg.UI
                        Select Case MessageType
                            Case Logging.MessageType.General
                                If Not IsNothing(DBLForm) Then DBLForm.TextBox1.BeginInvoke(New AddText(AddressOf AddItem1), New String() {Text})
                            Case Logging.MessageType.UI
                                If Not IsNothing(DBLForm) Then DBLForm.TextBox1.BeginInvoke(New AddText(AddressOf AddItem1), New String() {Text})
                        End Select
                    Case HighestShowableMsg.UpdateEngine
                        Select Case MessageType
                            Case Logging.MessageType.UpdateEngine_DL
                                If Not IsNothing(DBLForm) Then DBLForm.TextBox1.BeginInvoke(New AddText(AddressOf AddItem1), New String() {Text})
                            Case Logging.MessageType.General
                                If Not IsNothing(DBLForm) Then DBLForm.TextBox1.BeginInvoke(New AddText(AddressOf AddItem1), New String() {Text})
                            Case Logging.MessageType.UpdateEngine_Parsing
                                If Not IsNothing(DBLForm) Then DBLForm.TextBox1.BeginInvoke(New AddText(AddressOf AddItem1), New String() {Text})
                            Case Logging.MessageType.UpdateEngine_UI
                                If Not IsNothing(DBLForm) Then DBLForm.TextBox1.BeginInvoke(New AddText(AddressOf AddItem1), New String() {Text})
                        End Select
                End Select
            Catch ex As Exception
                'MsgBox(ex.ToString)
            End Try
        End Sub
        Private Sub AddItem1(ByVal Text As String)
            Try
#If DEBUG Then
                If DBLForm.TextBox1.Text = "" Then
                    DBLForm.TextBox1.Text = Text
                Else
                    DBLForm.TextBox1.AppendText(vbNewLine & Text)
                End If
#End If
            Catch ex As Exception
                '  MsgBox(ex.ToString)
                FileClose()
            End Try
        End Sub
        Public Property MinShowableLevel() As Object Implements Interfaces.ILogging.MinShowableLevel
            Get
                Return HighestShownMsg
            End Get
            Set(ByVal value As Object)
                HighestShownMsg = value
            End Set
        End Property
    End Class
End Namespace
